package com.qijian.maindata.domain;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qijian.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 产品定额申请单对象 main_quota_apply
 *
 * @author qijian
 * @date 2023-05-10
 */
@Data
@ToString
@TableName("main_quota_apply")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QuotaApply {
    private static final long serialVersionUID = 1L;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "id")
    private Long id;

    @Excel(name = "标题", sort = 1)
    @ApiModelProperty(value = "标题")
    private String title;

    @Excel(name = "流程编号", sort = 2)
    @ApiModelProperty(value = "流程编号")
    private String number;

    @Excel(name = "申请人", sort = 4)
    @ApiModelProperty(value = "申请人name")
    private String userName;

    @Excel(name = "部门", sort = 5)
    @ApiModelProperty(value = "部门name")
    private String deptName;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "申请日期", width = 30, dateFormat = "yyyy-MM-dd", sort = 6)
    @ApiModelProperty(value = "申请日期")
    private Date applyDate;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "到期日期", width = 30, dateFormat = "yyyy-MM-dd", sort = 7)
    @ApiModelProperty(value = "到期日期")
    private Date expireDate;

    @Excel(name = "单据类型", sort = 3)
    @ApiModelProperty(value = "单据类型")
    private String type;

    @Excel(name = "金蝶物料编码", sort = 11)
    @ApiModelProperty(value = "金蝶物料编码")
    private String kingdeeItemCode;

    @Excel(name = "产品名称", sort = 8)
    @ApiModelProperty(value = "产品名称")
    private String productName;

    @Excel(name = "开工令", sort = 9)
    @ApiModelProperty(value = "开工令")
    private String projectNo;

    @Excel(name = "机台号", sort = 10)
    @ApiModelProperty(value = "机台号")
    private String machineNo;

    @Excel(name = "重量", sort = 12)
    @ApiModelProperty(value = "重量")
    private BigDecimal weight;

    @Excel(name = "面积", sort = 13)
    @ApiModelProperty(value = "面积")
    private BigDecimal area;

    @Excel(name = "原定额(总)", sort = 14)
    @ApiModelProperty(value = "原定额(总)")
    private BigDecimal totalOriginalQuota;

    @Excel(name = "现定额(总)", sort = 15)
    @ApiModelProperty(value = "现定额(总)")
    private BigDecimal totalPresentQuota;

    @Excel(name = "实际时间-小时(总)", sort = 16)
    @ApiModelProperty(value = "实际时间-小时(总)")
    private BigDecimal totalActualHour;

    @ApiModelProperty(value = "是否发送了邮件")
    private Boolean isEmail;


    public static QuotaApply transitionFanWeiJsonObject(JSONObject obj) {
        QuotaApply build = QuotaApply.builder()
                .id(obj.getLong("requestid"))
                .title(obj.getStr("requestname"))
                .number(obj.getStr("field6731"))
                .userName(obj.getStr("field6727span"))
                .deptName(obj.getStr("field6729span"))
                .applyDate(obj.getDate("field6730"))
                .type(obj.getStr("field8692span"))
                .kingdeeItemCode(obj.getStr("field11149"))
                .productName(obj.getStr("field6732"))
                .projectNo(obj.getStr("field6733"))
                .machineNo(obj.getStr("field6734"))
                .weight(obj.getBigDecimal("field8689"))
                .area(obj.getBigDecimal("field8690"))
                .totalOriginalQuota(obj.getBigDecimal("field6737"))
                .totalPresentQuota(obj.getBigDecimal("field6738"))
                .totalActualHour(obj.getBigDecimal("field6739"))
                .build();
        if (build.getApplyDate() != null) {
            build.setExpireDate(DateUtil.date(build.getApplyDate()).offset(DateField.YEAR, 1));
        }
        return build;

    }
}

